package com.sky.config;

import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class OssConfiguration {

    @Bean
    public EnvironmentVariableCredentialsProvider environmentVariableCredentialsProvider() {
        try {
            return CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        } catch (com.aliyuncs.exceptions.ClientException e) {
            throw new RuntimeException("Failed to create EnvironmentVariableCredentialsProvider", e);
        }
    }
  /*  @Bean
    @ConditionalOnMissingBean
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties,EnvironmentVariableCredentialsProvider credentialsProvider) {
        log.info("6546465{}", aliOssProperties);
        log.info("465456644{}", credentialsProvider);
        //EnvironmentVariableCredentialsProvider environmentVariableCredentialsProvider = environmentVariableCredentialsProvider();
        return new AliOssUtil(aliOssProperties.getEndpoint(), aliOssProperties.getBucketName(), credentialsProvider);
    }*/

    /**
     * 环境密钥
     *
     * @return
     */

}
